/**
 * Project: complex.cs
 * 
 * File Created at 2010-7-1
 * $Id$
 * 
 * Copyright 2008 Alibaba.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package com.ymkyve.eraclient;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.concurrent.TimeUnit;

/**
 * @description:socket客户端
 * @author gaoliang
 * @date 2010-7-1
 * @version 1.0
 */
public class Client {
    public static void main(String[] args) {
        //建立与serverSocket的连接
        Socket socket = null;
        try {
            socket = new Socket("127.0.0.1", 998);
        } catch (UnknownHostException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        OutputStream out = new DataOutputStream(System.out);
        try {
            InputStream in = socket.getInputStream();
            while (true) {

                
                byte[] bRead = new byte[1024];
                int iRead;
                while ((iRead = in.read(bRead)) != -1) {
                    //写入输出流
                    out.write(bRead, 0, iRead);
                }
                TimeUnit.SECONDS.sleep(1);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                out.close();

                socket.close();

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
